const PostCompilePlugin = require('webpack-post-compile-plugin')
const TransformModulesPlugin = require('webpack-transform-modules-plugin')

module.exports = {
  devServer: {
    // 自动打开浏览器
    open: true,
    // host: '0.0.0.0',
    port: 8080,
    // vue访问后台服务的端口
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:8899',
        changeOrigin: true,
        pathRewrite: {
          '^/api': '/'
        }
      }
    }
  },
  chainWebpack: config => {
    const conf = config.toConfig()
    config
      .plugin('post-compile')
      .use(PostCompilePlugin, [{
        config: {
          module: {
            rules: [...conf.module.rules]
          }
        }
      }])
      .end()
      .plugin('transform-modules')
      .use(TransformModulesPlugin)
  },
  css: {
    loaderOptions: {
      stylus: {
        'resolve url': true
        // 自定义主题场景
        // import: [path.resolve(__dirname, './src/theme')]
      }
    }
  }
}
